package Classes.GameViews.ViewDisplayers.MapTargets
{
	import Classes.GameUtils.GU_DataTransform;
	import Classes.GameUtils.GU_GetBMPMC;
	import Classes.GameViews.GV_Map;
	import Classes.Interfaces.I_NeedSWFSource;
	import Classes.Managers.M_ConfigData;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.system.ApplicationDomain;
	import flash.utils.Timer;
	
	internal class TX_sprite extends Sprite implements I_NeedSWFSource
	{
		private var _tsp:Sprite;
		private var _txId:uint;
		private var _addtoTarget:MapTarget;
		private var _isOne:Boolean=true;//false;
		private var _delay:uint=0;
		public 		var _rotation:Number=0;
		public function TX_sprite(addtoTarget:MapTarget,txId:uint,delay:uint=0)
		{
			_addtoTarget	=	addtoTarget;
			_txId			=	txId;
			_tsp			=	addtoTarget;
			_delay			=	delay;
			super();
		}
		
		public function sourceLoadOver(sourceName:String):void
		{
			_tsp	=	new (ApplicationDomain.currentDomain.getDefinition(sourceName) as Class);
			this.addChild(_tsp);
			if(_rotation!=0){
				if( null!=_tsp.getChildByName("hx"))
					_tsp.getChildByName("hx").rotation	=	_rotation;
				else	
					_tsp.scaleX=-1; 								//静像
			}
			
			
			_addtoTarget.upDatePosition(this,TXObj[_txId].zt_tx_type);
			
			//解决第一次位置不正确
			if(!_isOne && _delay==0){
				_isOne=true;
				_addtoTarget.setState(_txId,false);
				
				var t:Timer=new Timer(100,1);
				t.addEventListener(TimerEvent.TIMER,function(e:Event):void{
					_addtoTarget.setState(_txId,true);
//					if(_delay!=0){
//						var tm:Timer	=	new Timer(_delay,1);
//						tm.addEventListener(TimerEvent.TIMER, function():void{_addtoTarget.setState(_txId,false);});
//						tm.start();
//					}
				});
				t.start();
			}
		}
		
		public function release():void
		{
			while(this.numChildren)this.removeChildAt(0);
			if(this.parent)this.parent.removeChild(this);
		}
		
		private static var _TXObj:Object;
		/**
		 * 特效配置表对象 
		 */
		public static function get TXObj():Object
		{
			if(null==_TXObj)
			{
				_TXObj=new Object();
				var configStr:String=M_ConfigData.instance.getCSVByName("特效静态表");
				var configArr:Array=GU_DataTransform.csvTransformObjsAry(configStr,4);
				for each (var obj:Object in configArr)
				{
					_TXObj[obj.zt_tx_id]=obj;
				}
			}
			return _TXObj;
		}
		
	}
}